/**
 * 倒置算法 123 -> 321.
 *
 * @author Xu Yayuan
 * @date 2022/3/4
 */
public class ReverseNum {
    public static void main(String[] args) {
        System.out.println(reverse(153423649));
    }
    public static int reverse(int num) {
        int rev=0;
        while (num != 0) {
            // 得到个位数
            int pop = num % 10;
            // 去掉个位数
            num /= 10;
            if (rev > Integer.MAX_VALUE/10) return 0;
            if (rev < Integer.MIN_VALUE/10) return 0;
            rev = rev * 10 + pop;
        }
        return rev;
    }
}
